function Button(x, y, w, h) {
    this.x = x;
    this.y = y;
    this.w = w;
    this.h = h;
    this.nc = '#E1E1E1';
    this.pc = '#FF0000';
    this.pressed = false;
}

(function() {
    function area(b, x, y) {
        return b.x <= x && (b.x + b.w) >= x && b.y <= y && (b.y + b.h) >= y;
    }

    Button.prototype.draw = function (ctx) {
        ctx.fillStyle = this.pressed ? this.pc : this.nc;
        ctx.fillRect(this.x, this.y, this.w, this.h);
    };
    
    Button.prototype.mousedown = function (x, y) {
        var test = area(this, x, y);
        if (test) this.pressed = true;
        return test;
    };
    
    Button.prototype.mousemove = function(x, y) {
        var test = area(this, x, y);
        if (!test && this.pressed) this.pressed = false;
    };
    
    Button.prototype.mouseup = function (x, y) {
        var test = area(this, x, y);
        if (test) {
            this.pressed = false;
            this.click && this.click(this);
        }
        return test;
    };
})();